package com.my.project.service.impl;

import com.my.project.mapper.UserMapper;
import com.my.project.model.User;
import com.my.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.UUID;

/**
 * @Author: lsg
 * @Date: Created 2018-07-14 10:13
 */
@Service
public class UserService implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Transactional
    @Override
    public int addUser(User user) {

        user.setUserId(UUID.randomUUID().toString().replace("-", "").trim());
        user.setCreateTime(new Date().getTime());
        user.setVersion(1);
        user.setRemark("");
        user.setStatus(1);
        return userMapper.addUser(user);
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }

    @Override
    public int delUserById(String userId) {
        return userMapper.delUserById(userId);
    }

    @Override
    public User getUserById(String userId) {
        return userMapper.getUserById(userId);
    }
}
